;
(function (window, angular) {
    'use strict';

    function isAllowI18n(scopeF) {
        // 判断当前页面是否允许国际化
        scopeF.multiLan = scopeF.$root.allowI18n;
    }

    angular.module("Directive.Selector", [])
        .directive("keeperSelector", ['$document', function ($document) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    selectedKeeper: "=?ngModel"
                },
                controller: 'KeeperSelectorCtrl',
                templateUrl: "js/directive/tpl/keeperSelector.html",
                link: function ($scope, element, attrs) {

                    isAllowI18n($scope);

                    $document.on('click', function () {
                        if (!!$scope.enablePopup) {
                            $scope.$apply(function () {
                                $scope.enablePopup = false;
                            });
                        }
                    });
                }
            }
        }])
        .controller("KeeperSelectorCtrl", ["$scope", "$attrs", "ybHttp", "ybWidget", "$timeout", function ($scope, $attrs, ybHttp, ybWidget, $timeout) {
            $scope.enablePopup = false;
            $scope.upPosition = angular.isDefined($attrs.popupPosition) ? ($attrs.popupPosition == 'up') : false;
            $scope.dataList = [];
            var keeperSelected = {};
            keeperSelected = angular.copy($scope.selectedKeeper);

            $scope.toggleDropDown = function () {
                if (!!$scope.enablePopup) {
                    return;
                }
                $scope.dataList = [];
                keeperSelected = angular.copy($scope.selectedKeeper);
                getDataList();
                $timeout(function () {
                    $scope.enablePopup = true;
                });
            };

            function setItemChecked() {
                if (!!keeperSelected.list && keeperSelected.list.length > 0) {
                    for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                        $scope.dataList[i].isChecked = false;
                        for (var j = 0, lengj = keeperSelected.list.length; j < lengj; j++) {
                            $scope.dataList[i].isChecked = false;
                            if ($scope.dataList[i].userId == keeperSelected.list[j]) {
                                $scope.dataList[i].isChecked = true;
                                break;
                            }
                        }
                    }
                }
            }

            function getDataList() {
                var service = "device";
                var reqUrl = "/inventoryCheck/selectUserByWarehouse";
                var param = {
                    warehouseCode: $scope.$parent.detailInfo.warehouseCode
                };
                ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value, function (item) {
                        item.isChecked = false;
                    });
                    $scope.dataList = resp.value;
                    setItemChecked();
                });
            }

            $scope.ok = function () {
                var selectedKeeper = [];
                var selectKeeperName = "";
                for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                    if (!!$scope.dataList[i].isChecked) {
                        selectedKeeper.push($scope.dataList[i].userId);
                        if (selectKeeperName === "") {
                            selectKeeperName = $scope.dataList[i].userName;
                        } else {
                            selectKeeperName = selectKeeperName + "," + $scope.dataList[i].userName;
                        }
                    }
                }
                $scope.selectedKeeper = {
                    list: selectedKeeper,
                    name: selectKeeperName
                };
                closePopup();
            };

            $scope.cancel = function () {
                closePopup();
            };

            function closePopup() {
                $scope.enablePopup = false;
            }
        }])
        .directive("locationSelector", ['$document', function ($document) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    selectedLocation: "=?ngModel"
                },
                controller: 'LocationSelectorCtrl',
                templateUrl: "js/directive/tpl/locationSelector.html",
                link: function ($scope, element, attrs) {
                    $document.on('click', function () {
                        if (!!$scope.enablePopup) {
                            $scope.$apply(function () {
                                $scope.enablePopup = false;
                            });
                        }
                    });
                }
            }
        }])
        .controller("LocationSelectorCtrl", ["$scope", "$attrs", "ybHttp", "ybWidget", "$timeout", "MESG_TYPE", function ($scope, $attrs, ybHttp, ybWidget, $timeout, MESG_TYPE) {
            $scope.enablePopup = false;
            $scope.upPosition = angular.isDefined($attrs.popupPosition) ? ($attrs.popupPosition == 'up') : false;
            $scope.dataList = [];
            var locationSelected = {};
            locationSelected = angular.copy($scope.selectedLocation);

            $scope.toggleDropDown = function () {
                if (!$scope.$parent.detailInfo.warehouseId) {
                    ybWidget.ShowMessage("请选择仓库", MESG_TYPE.Error);
                    return;
                }
                if (!!$scope.enablePopup) {
                    return;
                }
                locationSelected = angular.copy($scope.selectedLocation);
                getDataList();
                $timeout(function () {
                    $scope.enablePopup = true;
                });
            };

            function setItemChecked() {
                if (!!locationSelected.list && locationSelected.list.length > 0) {
                    for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                        $scope.dataList[i].isChecked = false;
                        for (var j = 0, lengj = locationSelected.list.length; j < lengj; j++) {
                            $scope.dataList[i].isChecked = false;
                            if ($scope.dataList[i].areaCode == locationSelected.list[j]) {
                                $scope.dataList[i].isChecked = true;
                                break;
                            }
                        }
                    }
                }
            }

            function getDataList() {
                var service = "device";
                var reqUrl = "/warehouse/listAreas";
                var param = {
                    pageNum: 0,
                    pageSize: 0,
                    warehouseId: $scope.$parent.detailInfo.warehouseId
                };
                ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.isChecked = false;
                    });
                    $scope.dataList = resp.value.list;
                    setItemChecked();
                });
            }

            $scope.ok = function () {
                var selectedLocation = [];
                var selectLocationName = "";
                for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                    if (!!$scope.dataList[i].isChecked) {
                        selectedLocation.push($scope.dataList[i].areaCode);
                        if (selectLocationName === "") {
                            selectLocationName = $scope.dataList[i].areaCode;
                        } else {
                            selectLocationName = selectLocationName + "," + $scope.dataList[i].areaCode;
                        }
                    }
                }
                $scope.selectedLocation = {
                    list: selectedLocation,
                    name: selectLocationName
                };
                closePopup();
            };

            $scope.cancel = function () {
                closePopup();
            };

            function closePopup() {
                $scope.enablePopup = false;
            }
        }])
        .directive("maintenanceSelector", ['$document', '$timeout', function ($document, $timeout) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    maintenanceList: "=?maintenanceList",
                    selectModelName: "=?selectModelName",
                    boxClick: "&"
                },
                templateUrl: "js/directive/tpl/maintenanceSelector.html",
                link: function ($scope, element, attrs) {
                    $document.on('click', function () {
                        if (!!$scope.enablePopup) {
                            $scope.$apply(function () {
                                $scope.enablePopup = false;
                            });
                        }
                    });
                    $scope.toggleDropDown = function () {
                        if (!!$scope.enablePopup) {
                            return;
                        }
                        $timeout(function () {
                            $scope.enablePopup = true;
                        });
                    };
                }
            }
        }])
        .directive("checkBoxSelector", ['$document', '$timeout', '$window', function ($document, $timeout, $window) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    selectedValue: "=?ngModel",
                    dataList: "=?valueList",
                    defaultValue: "@",
                    boxClick: "&"
                },
                templateUrl: "js/directive/tpl/checkBoxSelector.html",
                link: function ($scope, element, attrs) {
                    function enablePopup() {
                        if (!!$scope.enablePopup) {
                            $scope.$apply(function () {
                                $scope.enablePopup = false;
                            });
                        }
                    }
                    angular.element($document[0].querySelector('.more-toolbar')).on('click', function () {
                        enablePopup();
                    });
                    $document.on('click', function () {
                        enablePopup();
                    });
                    $scope.toggleDropDown = function () {
                        $timeout(function () {
                            $scope.enablePopup = !$scope.enablePopup;
                        });
                    };
                }
            }
        }])
        .directive("cascadeSelector", ['$document', function ($document) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    selectedObj: "=?ngModel"
                },
                controller: 'CascadeSelectorCtrl',
                templateUrl: "js/directive/tpl/cascadeSelector.html",
                link: function ($scope, element, attrs) {

                    isAllowI18n($scope);

                    $document.on('click', function () {
                        if (!!$scope.enablePopup) {
                            $scope.$apply(function () {
                                $scope.enablePopup = false;
                            });
                        }
                    });
                }
            }
        }])
        .controller("CascadeSelectorCtrl", ["$scope", "$attrs", "ybHttp", "ybWidget", "$timeout", function ($scope, $attrs, ybHttp, ybWidget, $timeout) {
            $scope.enablePopup = false;
            $scope.activeFlag = [true, false, false];
            $scope.firstClassList = [];
            $scope.secondClassList = [];
            $scope.thirdClassList = [];
            $scope.upPosition = angular.isDefined($attrs.popupPosition) ? ($attrs.popupPosition == 'up') : false;
            $scope.selectedObjShow = {
                warehouseId: "",
                warehouseCode: "",
                areaId: "",
                areaCode: "",
                locationCode: ""
            };

            function getFirstList() {
                var service = "device";
                var reqUrl = "/warehouse/listWarehouses";
                var param = {};
                param.pageSize = 0;
                param.pageNum = 0;
                return ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code != 0) {
                        ybWidget.ShowMessage(resp);
                        return false;
                    }
                    return resp.value.list;
                })
            }

            function getSecondList(item) {
                var service = "device";
                var reqUrl = "/warehouse/listAreas";
                var param = {};
                param.pageSize = 0;
                param.pageNum = 0;
                param.warehouseId = item.id;
                return ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code != 0) {
                        ybWidget.ShowMessage(resp);
                        return false;
                    }
                    return resp.value.list;
                })
            }

            function getThirdList(item) {
                var service = "device";
                var reqUrl = "/warehouse/listShlefNos";
                var param = {};
                param.pageSize = 0;
                param.pageNum = 0;
                param.areaId = item.id;
                return ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code != 0) {
                        ybWidget.ShowMessage(resp);
                        return false;
                    }
                    return resp.value.list;
                })
            }

            $scope.toggleDropDown = function () {
                if (!!$scope.enablePopup) {
                    return;
                }
                getFirstList().then(function (data) {
                    if (!!data) {
                        $scope.firstClassList = data;
                    }
                });
                $timeout(function () {
                    $scope.enablePopup = true;
                });
            };

            $scope.changeTab = function (tab) {
                for (var i = 0; i < $scope.activeFlag.length; i++) {
                    $scope.activeFlag[i] = false;
                }
                $scope.activeFlag[tab] = true;
            };

            $scope.changeTabFn = function (tab) {
                switch (tab) {
                    case 0:
                        $scope.secondClassList = [];
                        $scope.thirdClassList = [];
                        $scope.selectedObjShow.areaId = "";
                        $scope.selectedObjShow.areaCode = "";
                        $scope.selectedObjShow.locationCode = "";
                        break;
                    case 1:
                        $scope.thirdClassList = [];
                        $scope.selectedObjShow.locationCode = "";
                        break;
                    case 2:
                        break;
                    default:
                        break;
                }
            };

            $scope.selectClassItem = function (rank, item) {
                if ($scope.$parent.isKJ) {

                    switch (rank) {
                        case 0:
                            $scope.selectedObjShow.warehouseId = item.id;
                            $scope.selectedObjShow.warehouseCode = item.warehouseCode;
                            $scope.secondClassList = [];
                            getSecondList(item).then(function (data) {
                                if (!!data) {
                                    $scope.secondClassList = data;
                                    $scope.changeTab(1);
                                }
                            });
                            break;
                        case 1:
                            $scope.selectedObjShow.areaId = item.id;
                            $scope.selectedObjShow.areaCode = item.areaCode;
                            $scope.thirdClassList = [];
                            // getThirdList(item).then(function (data) {
                            //     if (!!data) {
                            //         $scope.thirdClassList = data;
                            //         $scope.changeTab(2);
                            //     }
                            // });
                            $scope.selectedObjShow.locationCode = " ";
                            break;
                        case 2:
                            $scope.selectedObjShow.locationCode = item.shelfNo;
                            break;
                        default:
                            break;
                    }
                } else {

                    switch (rank) {
                        case 0:
                            $scope.selectedObjShow.warehouseId = item.id;
                            $scope.selectedObjShow.warehouseCode = item.warehouseCode;
                            $scope.secondClassList = [];
                            getSecondList(item).then(function (data) {
                                if (!!data) {
                                    $scope.secondClassList = data;
                                    $scope.changeTab(1);
                                }
                            });
                            break;
                        case 1:
                            $scope.selectedObjShow.areaId = item.id;
                            $scope.selectedObjShow.areaCode = item.areaCode;
                            $scope.thirdClassList = [];
                            getThirdList(item).then(function (data) {
                                if (!!data) {
                                    $scope.thirdClassList = data;
                                    $scope.changeTab(2);
                                }
                            });
                            break;
                        case 2:
                            $scope.selectedObjShow.locationCode = item.shelfNo;
                            break;
                        default:
                            break;
                    }
                }
            };

            $scope.clearDepot = function () {
                $scope.changeTab(0);
                $scope.secondClassList = [];
                $scope.thirdClassList = [];
                $scope.selectedObjShow.warehouseId = "";
                $scope.selectedObjShow.warehouseCode = "";
                $scope.selectedObjShow.areaId = "";
                $scope.selectedObjShow.areaCode = "";
                $scope.selectedObjShow.locationCode = "";
                $scope.selectedObj.warehouseId = "";
                $scope.selectedObj.warehouseCode = "";
                $scope.selectedObj.areaId = "";
                $scope.selectedObj.areaCode = "";
                $scope.selectedObj.locationCode = "";
            };

            $scope.ok = function () {
                $scope.selectedObj.warehouseId = $scope.selectedObjShow.warehouseId;
                $scope.selectedObj.warehouseCode = $scope.selectedObjShow.warehouseCode;
                $scope.selectedObj.areaId = $scope.selectedObjShow.areaId;
                $scope.selectedObj.areaCode = $scope.selectedObjShow.areaCode;
                $scope.selectedObj.locationCode = $scope.selectedObjShow.locationCode;
                closePopup();
            };


            $scope.cancel = function () {
                closePopup();
            };

            function closePopup() {
                $scope.enablePopup = false;
            }

        }])

        .directive("departmentSelector", ['$document', function ($document) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    selectedObj: "=ngModel"
                },
                controller: 'DepartmentSelectorCtrl',
                templateUrl: "js/directive/tpl/departmentSelector.html",
                link: function ($scope, element, attrs) {

                    isAllowI18n($scope);

                    $document.on('click', function () {
                        if (!!$scope.enablePopup) {
                            $scope.$apply(function () {
                                $scope.enablePopup = false;
                            });
                        }
                    });
                }
            }
        }])
        .controller("DepartmentSelectorCtrl", ["$scope", "$attrs", "ybHttp", "ybWidget", "$timeout", function ($scope, $attrs, ybHttp, ybWidget, $timeout) {
            $scope.enablePopup = false;
            $scope.activeFlag = [true, false, false];
            $scope.firstClassList = [];
            $scope.secondClassList = [];
            $scope.thirdClassList = [];
            $scope.tabObj = [];
            $scope.upPosition = angular.isDefined($attrs.popupPosition) ? ($attrs.popupPosition == 'up') : false;

            function getDealerClassList(id) {
                var service = "auth";
                var reqUrl = "/department/list";
                var param = {};
                param.id = id;
                return ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code != 0) {
                        ybWidget.ShowMessage(resp);
                        return;
                    }
                    return resp.value;
                })
            }

            $scope.toggleDropDown = function () {
                if (!!$scope.enablePopup) {
                    return;
                }
                getDealerClassList("0").then(function (data) {
                    if (!!data) {
                        $scope.firstClassList = data;
                    }
                });
                $timeout(function () {
                    $scope.enablePopup = true;
                });
            };

            $scope.changeTab = function (tab) {
                for (var i = 0; i < $scope.activeFlag.length; i++) {
                    $scope.activeFlag[i] = false;
                }
                $scope.activeFlag[tab] = true;
            };

            $scope.selectClassItem = function (rank, item) {
                switch (rank) {
                    case 1:
                        $scope.tabObj = [];
                        $scope.tabObj[0] = item;
                        $scope.secondClassList = [];
                        $scope.thirdClassList = [];
                        getDealerClassList(item.id).then(function (data) {
                            if (!!data) {
                                $scope.secondClassList = data;
                                if ($scope.secondClassList.length > 0) {
                                    $scope.changeTab(1);
                                }
                            }
                        });
                        break;
                    case 2:
                        $scope.tabObj.length = 2;
                        $scope.tabObj[1] = item;
                        $scope.thirdClassList = [];
                        getDealerClassList(item.id).then(function (data) {
                            if (!!data) {
                                $scope.thirdClassList = data;
                                if ($scope.thirdClassList.length > 0) {
                                    $scope.changeTab(2);
                                }
                            }
                        });
                        break;
                    case 3:
                        $scope.tabObj[2] = item;
                        break;
                    default:
                        break;
                }
            };

            $scope.ok = function () {
                var lastIndex = $scope.tabObj.length - 1;
                if (lastIndex >= 0) {
                    $scope.selectedObj.departName = $scope.tabObj[lastIndex].name;
                    $scope.selectedObj.id = $scope.tabObj[lastIndex].id;
                }
                closePopup();
            };

            $scope.cancel = function () {
                closePopup();
            };

            function closePopup() {
                $scope.enablePopup = false;
            }

        }])
        .directive("supplierClassSelector", ['$document', function ($document) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    selectedObj: "=ngModel"
                },
                controller: 'SupplierClassSelectorCtrl',
                templateUrl: "js/directive/tpl/supplierClassSelector.html",
                link: function ($scope, element, attrs) {
                    $document.on('click', function () {
                        if (!!$scope.enablePopup) {
                            $scope.$apply(function () {
                                $scope.enablePopup = false;
                            });
                        }
                    });
                }
            }
        }])
        .controller("SupplierClassSelectorCtrl", ["$scope", "$attrs", "ybHttp", "ybWidget", "$timeout", function ($scope, $attrs, ybHttp, ybWidget, $timeout) {
            $scope.enablePopup = false;
            $scope.activeFlag = [true, false, false];
            $scope.firstClassList = [];
            $scope.secondClassList = [];
            $scope.thirdClassList = [];
            $scope.tabObj = [];
            $scope.upPosition = angular.isDefined($attrs.popupPosition) ? ($attrs.popupPosition == 'up') : false;

            function getDealerClassList(id) {
                var service = "device";
                var reqUrl = "/supplierClass/list";
                var param = {};
                param.pId = id;
                return ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code != 0) {
                        ybWidget.ShowMessage(resp);
                        return;
                    }
                    return resp.value;
                })
            }

            $scope.toggleDropDown = function () {
                if (!!$scope.enablePopup) {
                    return;
                }
                getDealerClassList("0").then(function (data) {
                    if (!!data) {
                        $scope.firstClassList = data;
                    }
                });
                $timeout(function () {
                    $scope.enablePopup = true;
                });
            };

            $scope.changeTab = function (tab) {
                for (var i = 0; i < $scope.activeFlag.length; i++) {
                    $scope.activeFlag[i] = false;
                }
                $scope.activeFlag[tab] = true;
            };

            $scope.selectClassItem = function (rank, item) {
                switch (rank) {
                    case 1:
                        $scope.tabObj = [];
                        $scope.tabObj[0] = item;
                        $scope.secondClassList = [];
                        $scope.thirdClassList = [];
                        getDealerClassList(item.id).then(function (data) {
                            if (!!data) {
                                $scope.secondClassList = data;
                                if ($scope.secondClassList.length > 0) {
                                    $scope.changeTab(1);
                                }
                            }
                        });
                        break;
                    case 2:
                        $scope.tabObj.length = 2;
                        $scope.tabObj[1] = item;
                        $scope.thirdClassList = [];
                        getDealerClassList(item.id).then(function (data) {
                            if (!!data) {
                                $scope.thirdClassList = data;
                                if ($scope.thirdClassList.length > 0) {
                                    $scope.changeTab(2);
                                }
                            }
                        });
                        break;
                    case 3:
                        $scope.tabObj[2] = item;
                        break;
                    default:
                        break;
                }
            };

            $scope.ok = function () {
                var lastIndex = $scope.tabObj.length - 1;
                if (lastIndex >= 0) {
                    $scope.selectedObj.className = $scope.tabObj[lastIndex].className;
                    $scope.selectedObj.id = $scope.tabObj[lastIndex].id;
                }
                closePopup();
            };

            $scope.cancel = function () {
                closePopup();
            };

            function closePopup() {
                $scope.enablePopup = false;
            }

        }])
        .directive("dealerClassSelector", ['$document', function ($document) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    selectedObj: "=ngModel"
                },
                controller: 'DealerClassSelectorCtrl',
                templateUrl: "js/directive/tpl/dealerClassSelector.html",
                link: function ($scope, element, attrs) {
                    isAllowI18n($scope);

                    $document.on('click', function () {
                        if (!!$scope.enablePopup) {
                            $scope.$apply(function () {
                                $scope.enablePopup = false;
                            });
                        }
                    });
                }
            }
        }])
        .controller("DealerClassSelectorCtrl", ["$scope", "$attrs", "ybHttp", "ybWidget", "$timeout", function ($scope, $attrs, ybHttp, ybWidget, $timeout) {
            $scope.enablePopup = false;
            $scope.activeFlag = [true, false, false];
            $scope.firstClassList = [];
            $scope.secondClassList = [];
            $scope.thirdClassList = [];
            $scope.tabObj = [];
            $scope.upPosition = angular.isDefined($attrs.popupPosition) ? ($attrs.popupPosition == 'up') : false;

            function getDealerClassList(id) {
                var service = "device";
                var reqUrl = "/dealerClass/list";
                var param = {};
                param.pId = id;
                return ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code != 0) {
                        ybWidget.ShowMessage(resp);
                        return;
                    }
                    return resp.value;
                })
            }

            $scope.toggleDropDown = function () {
                if (!!$scope.enablePopup) {
                    return;
                }
                getDealerClassList("0").then(function (data) {
                    if (!!data) {
                        $scope.firstClassList = data;
                    }
                });
                $timeout(function () {
                    $scope.enablePopup = true;
                });
            };

            $scope.changeTab = function (tab) {
                for (var i = 0; i < $scope.activeFlag.length; i++) {
                    $scope.activeFlag[i] = false;
                }
                $scope.activeFlag[tab] = true;
            };

            $scope.selectClassItem = function (rank, item) {
                switch (rank) {
                    case 1:
                        $scope.tabObj = [];
                        $scope.tabObj[0] = item;
                        $scope.secondClassList = [];
                        $scope.thirdClassList = [];
                        getDealerClassList(item.id).then(function (data) {
                            if (!!data) {
                                $scope.secondClassList = data;
                                if ($scope.secondClassList.length > 0) {
                                    $scope.changeTab(1);
                                }
                            }
                        });
                        break;
                    case 2:
                        $scope.tabObj.length = 2;
                        $scope.tabObj[1] = item;
                        $scope.thirdClassList = [];
                        getDealerClassList(item.id).then(function (data) {
                            if (!!data) {
                                $scope.thirdClassList = data;
                                if ($scope.thirdClassList.length > 0) {
                                    $scope.changeTab(2);
                                }
                            }
                        });
                        break;
                    case 3:
                        $scope.tabObj[2] = item;
                        break;
                    default:
                        break;
                }
            };

            $scope.ok = function () {
                var lastIndex = $scope.tabObj.length - 1;
                if (lastIndex >= 0) {
                    $scope.selectedObj.className = $scope.tabObj[lastIndex].className;
                    $scope.selectedObj.id = $scope.tabObj[lastIndex].id;
                }
                closePopup();
            };

            $scope.cancel = function () {
                closePopup();
            };

            function closePopup() {
                $scope.enablePopup = false;
            }

        }])

        .directive("materielClassSelector", ['$document', function ($document) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    selectedObj: "=ngModel",
                    dropdownIcon: "@",
                    cleanIcon: "@",
                    supplierOrgId: "=",
                    ngDisabled: "="
                },
                controller: 'MaterielClassSelectorCtrl',
                templateUrl: "js/directive/tpl/materielClassSelector.html",
                link: function ($scope, element, attrs) {

                    isAllowI18n($scope);

                    $document.on('click', function () {
                        if (!!$scope.enablePopup) {
                            $scope.$apply(function () {
                                $scope.enablePopup = false;
                            });
                        }
                    });
                }
            }
        }])

        .controller("MaterielClassSelectorCtrl", ["$scope", "$attrs", "ybHttp", "ybWidget", "$timeout", function ($scope, $attrs, ybHttp, ybWidget, $timeout) {
            $scope.enablePopup = false;
            $scope.activeFlag = [true, false, false];
            $scope.firstClassList = [];
            $scope.secondClassList = [];
            $scope.thirdClassList = [];
            $scope.tabObj = [];
            $scope.upPosition = angular.isDefined($attrs.popupPosition) ? ($attrs.popupPosition == 'up') : false;

            $scope.toggleDropDown = function () {
                if (!!$scope.enablePopup || $scope.ngDisabled) {
                    return;
                }
                getDealerClassList("0").then(function (data) {
                    if (!!data) {
                        $scope.firstClassList = data;
                    }
                });
                $timeout(function () {
                    $scope.enablePopup = true;
                });
            };
            $scope.changeTab = function (tab) {
                for (var i = 0; i < $scope.activeFlag.length; i++) {
                    $scope.activeFlag[i] = false;
                }
                $scope.activeFlag[tab] = true;
            };
            $scope.selectClassItem = function (rank, item) {
                switch (rank) {
                    case 1:
                        $scope.tabObj = [];
                        $scope.tabObj[0] = item;
                        $scope.secondClassList = [];
                        $scope.thirdClassList = [];
                        getDealerClassList(item.id).then(function (data) {
                            if (!!data) {
                                $scope.secondClassList = data;
                                if ($scope.secondClassList.length > 0) {
                                    $scope.changeTab(1);
                                }
                            }
                        });
                        break;
                    case 2:
                        $scope.tabObj.length = 2;
                        $scope.tabObj[1] = item;
                        $scope.thirdClassList = [];
                        getDealerClassList(item.id).then(function (data) {
                            if (!!data) {
                                $scope.thirdClassList = data;
                                if ($scope.thirdClassList.length > 0) {
                                    $scope.changeTab(2);
                                }
                            }
                        });
                        break;
                    case 3:
                        $scope.tabObj[2] = item;
                        break;
                    default:
                        break;
                }
            };
            $scope.ok = function () {
                var lastIndex = $scope.tabObj.length - 1;
                if (lastIndex >= 0) {
                    $scope.selectedObj.materialsType = $scope.tabObj[lastIndex].materialCalssName;
                    $scope.selectedObj.materialsTypeId = $scope.tabObj[lastIndex].id;
                }
                closePopup();
            };
            $scope.cancel = function () {
                closePopup();
            };
            $scope.cleanSelect = function (e) {
                e.stopPropagation();
                $scope.selectedObj.materialsType = undefined;
                $scope.selectedObj.materialsTypeId = undefined;
                $scope.tabObj = [];
            };

            function getDealerClassList(id) {
                var service = "device";
                var reqUrl = "/materialClass/list";
                var param = {};
                param.pId = id;
                if (!!$scope.supplierOrgId) {
                    param.orgId = $scope.supplierOrgId;
                }
                return ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code != 0) {
                        ybWidget.ShowMessage(resp);
                        return;
                    }
                    return resp.value;
                })
            }

            function closePopup() {
                $scope.enablePopup = false;
            }
        }])

        .directive("materielSelector", ['$document', function ($document) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    showToolbar: '=',
                    selectedList: "=",
                    warehouseCode: "=",
                    warehouseCodeOther: "=",
                    areaCode: "=",
                    isInventory: "=",
                    isPurchase: "=",
                    isDefaultWarehouse: "=",
                    dealerId: "=",
                    supplierId: '=',
                    supplierType: '=',
                    goalType: "@",
                    isReturnApply: "=",
                    replaceCheck: "@",
                    replaceOrRetrofitCheck: "@",
                    soldOrgId: "=",
                    markStockStatus: "=",
                },
                controller: 'MaterielSelectorCtrl',
                templateUrl: "js/directive/tpl/materielSelector.html",
                link: function (scope, element, attrs) {

                    isAllowI18n(scope);

                    $document.on('click', function () {
                        if (!!scope.showToolbar) {
                            if (scope.$root.isJCHK) {
                                return;
                            }

                            scope.$apply(function () {
                                scope.showToolbar = false;
                            });
                        }
                    });
                }
            }
        }])
        .controller("MaterielSelectorCtrl", ["$scope", "$attrs", "ybHttp", "ybWidget", "$timeout", "UserContextService", "EventBus", "$filter", "MESG_TYPE", "ybConfig", function ($scope, $attrs, ybHttp, ybWidget, $timeout, UserContextService, EventBus, $filter, MESG_TYPE, ybConfig) {
            var comparedStr = "materialsNo";

            $scope.dataList = [];
            $scope.condition = {
                keyWords: ''
            };
            $scope.mPageInfo = {
                pageSize: 10,
                pageNum: 1,
                curPage: 1,
                totalRows: 0,
                totalPages: 0,
                hidePageJump: true,
                hidePageNo: true
            };

            var getMaterielList = function (curPage) {
                var service = "device";
                var reqUrl = "/materials/list";
                
                if (!!curPage) {
                    $scope.mPageInfo.curPage = curPage;
                }
                var param = {
                    pageSize: $scope.mPageInfo.pageSize,
                    pageNum: $scope.mPageInfo.curPage,
                    filters: $scope.condition
                };

                if ($scope.isInventory) {
                    reqUrl = "/materials/listByCode";
                    comparedStr = "barCode";
                }
                if ($scope.isPurchase) {
                    param.filters.supplierOrgId = $scope.soldOrgId;
                    param.filters.orgId = $scope.soldOrgId;
                    reqUrl = "/materials/purchaseMaterialsList";
                }
                if ($scope.isDefaultWarehouse) {
                    reqUrl = "/materials/listForOut";
                }

                param.filters.warehouseCode = $scope.warehouseCode;
                param.filters.warehouseCodeOther = $scope.warehouseCodeOther;
                param.filters.areaCode = $scope.areaCode;

                if (!!$scope.supplierId) {
                    param.filters.orgId = $scope.supplierId;
                }
                if (!!$scope.dealerId) {
                    param.filters.dealerOrgId = $scope.dealerId;
                }

                if (['22', '33'].includes($scope.$root.curOrgType)) {
                    reqUrl = '/materials/querySupplierMaterials';
                }

                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code != 0) {
                        ybWidget.ShowMessage(resp);
                        return;
                    }
                    $scope.dataList = resp.value.list;
                    $scope.mPageInfo.totalRows = resp.value.total;
                    $scope.mPageInfo.totalPages = resp.value.pages;
                    angular.forEach($scope.dataList, function (item) {
                        item.isSelected = false;
                        item.price = $filter("decimalCover")(item.price, 2);
                        angular.forEach($scope.selectedList, function (item2) {
                            if (item[comparedStr] == item2[comparedStr]) {
                                item.isSelected = true;
                                if (item2.checkDisable) {
                                    item.checkDisable = true;
                                }
                            }
                        })
                    });
                })
            };

            $scope.search = UserContextService.Debounce(function () {
                getMaterielList(1);
            }, 500);

            $scope.changePage = function (curPage) {
                getMaterielList(curPage);
            };

            $scope.choseMateriel = function (item) {
                var selItem = {};
                if (item.isSelected) {
                    if ($scope.replaceCheck) {
                        if (item.replaceMaterialsNo) {
                            ybWidget.ShowToaster('info', '提示', '您所提交的' + item.materialsDes + '可以被' + item.replaceMaterialsDes +
                                '（' + item.replaceMaterialsNo + '）替代');
                        }
                    } else if ($scope.replaceOrRetrofitCheck) {
                        if (item.replaceMaterialsNo && item.retrofitMaterialsNo) {
                            ybWidget.ShowToaster('info', '提示', '您所提交的' + item.materialsDes + '已改型为' + item.retrofitMaterialsDes +
                                '（' + item.retrofitMaterialsNo + '），可以被 ' + item.replaceMaterialsDes + '（' + item.replaceMaterialsNo + '）替代，请核实');
                        } else if (item.replaceMaterialsNo) {
                            ybWidget.ShowToaster('info', '提示', '您所提交的' + item.materialsDes + '可以被' + item.replaceMaterialsDes +
                                '（' + item.replaceMaterialsNo + '）替代，请核实');
                        } else if (item.retrofitMaterialsNo) {
                            ybWidget.ShowToaster('info', '提示', '您所提交的' + item.materialsDes + '已改型为' + item.replaceMaterialsDes +
                                '（' + item.replaceMaterialsNo + '），请核实');
                        }
                    }
                    let df = "yyyy-MM-dd HH:mm:ss";
                    selItem.isChecked = false;
                    selItem.barCode = item.barCode;
                    selItem.marketingActivityPriceVOList = item.marketingActivityPriceVOList;
                    selItem.dealerMarketingActivityList = item.dealerMarketingActivityList;
                    selItem.materialsId = item.materialsId;
                    selItem.materialsNo = item.materialsNo;
                    selItem.materialNo = item.materialsNo;
                    selItem.materialsDes = item.materialsDes;
                    selItem.materialName = item.materialsDes;
                    selItem.materialsShortNo = item.materialsShortNo;
                    selItem.materialsDesc = item.materialsDes;
                    selItem.materialsDesEn = item.materialsDesEn;
                    selItem.materialsType = item.materialsType;
                    selItem.unit = item.unit;
                    selItem.price = item.price;
                    selItem.customMaterialsNo = item.customMaterialsNo;
                    selItem.replaceMaterialsDes = item.replaceMaterialsDes;
                    selItem.replaceMaterialsNo = item.replaceMaterialsNo;
                    selItem.replaceMaterialsNote = item.replaceMaterialsNote;
                    selItem.retrofitMaterialsDes = item.retrofitMaterialsDes;
                    selItem.retrofitMaterialsNo = item.retrofitMaterialsNo;
                    selItem.enableNum = item.enableNum;
                    selItem.enableNumOther = item.enableNumOther;
                    selItem.intentionNum = item.intentionNum;
                    selItem.deliveryNum = item.deliveryNum;
                    selItem.userName = item.userName;
                    selItem.priceSchemeId = item.priceSchemeId;
                    selItem.priceSchemeName = item.priceSchemeName;
                    selItem.amount = item.amount;
                    selItem.minimumBuy = item.minimumBuy;
                    selItem.isMinimumBuy = item.isMinimumBuy;
                    selItem.sendQty = item.sendQty;
                    selItem.realQty = item.realQty;
                    selItem.productPropClass = item.productPropClass;
                    selItem.noDeliveredQty = item.noDeliveredQty;
                    selItem.thisYearPurchaseAmount = item.thisYearPurchaseAmount;
                    selItem.standDeliveryTime = item.standDeliveryTime;

                    selItem.standardPrice = item.standardPrice ? item.standardPrice : 0;
                    selItem.sourcePrice = item.price;
                    selItem.locationCode = item.stockLocation;
                    selItem.totalStock = item.amount;

                    selItem.qty = 1;
                    selItem.quantity = 1;
                    selItem.amountAfterAdjust = 1;
                    selItem.applyQty = 1;

                    if (!$scope.$root.isDL && !$scope.$root.isZHL) {
                        // 非道路、筑路 赋默认值
                        selItem.deliveryDate = new Date();
                        selItem.requestDeliveryDate = new Date();
                    }

                    // 增加 外部库存功能
                    selItem.outWarehouseVO = item.outWarehouseVO;
                    selItem.totalOuter = item?.outWarehouseVO?.totalOuter;
                    selItem.totalInner = item?.outWarehouseVO?.innerWarehouse;

                    selItem.otherDealerStock = item.otherDealerStock;

                    selItem.costPrice = $filter("decimalPlaces")(selItem.standardPrice, 2);
                    selItem.costSubtotal = $filter("decimalCover")(ybWidget.Times(selItem.costPrice, selItem.qty), 2);
                    selItem.lastPurchaseTime = $filter("YbDate")(item.lastPurchaseTime, df);
                    selItem.estimatedShippingDateShow = $filter("YbDate")(item.estimatedShippingDate, df);

                    if (!!item.settlementPrice || item.settlementPrice === 0) {
                        selItem.settlementPrice = item.settlementPrice; // 成交价（折后价）
                        selItem.unitPriceAfterAdjust = item.settlementPrice;
                        selItem.applyTotalPrice = $filter("decimalCover")(ybWidget.Times(item.settlementPrice, selItem.qty), 2);
                        selItem.totalPriceAfterAdjust = $filter("decimalCover")(ybWidget.Times(item.settlementPrice, selItem.qty), 2);
                    }

                    if ($scope.goalType == "salesSlip") {
                        selItem.unitPriceAfterAdjust = item.price;
                        selItem.applyTotalPrice = $filter("decimalCover")(ybWidget.Times(item.price, selItem.qty), 2);
                        selItem.totalPriceAfterAdjust = $filter("decimalCover")(ybWidget.Times(item.price, selItem.qty), 2);
                    }

                    if ($scope.goalType == "sell") {
                        selItem.applyTotalPrice = $filter("decimalCover")(ybWidget.Times(item.price, selItem.qty), 2);
                    }
                    if ($scope.goalType == "back") {
                        selItem.totalPrice = $filter("decimalCover")(ybWidget.Times(item.price, selItem.qty), 2);
                    }
                    if ($scope.isReturnApply && !!item.settlementPrice) {
                        selItem.price = item.settlementPrice;
                    }
                    if ($scope.markStockStatus) { //标记当前库存值状态
                        UserContextService.SetStockStatusFlag(selItem, selItem.qty);
                    }
                    if($scope.supplierType == 'ZX'){
                        angular.forEach(item.marketingActivityPriceVOList,function(priceItem){
                            if(priceItem.name == '经销商价'){
                                selItem.priceSchemeName = '经销商价';
                                selItem.priceSchemeId = priceItem.activityId;
                                selItem.settlementPrice = priceItem.price;
                            }
                        })
                    }

                    EventBus.Publish("onMaterialSelect", selItem);

                    $scope.selectedList.push(selItem);
                } else {
                    for (var i = 0; i < $scope.selectedList.length; i++) {
                        if ($scope.selectedList[i][comparedStr] == item[comparedStr]) {
                            $scope.selectedList.splice(i, 1);
                        }
                    }
                }
                EventBus.Publish("onMaterialChange", { selectedDatas: $scope.selectedList, selectedItem: selItem });
            };

            function getMaterial(data) {
                $scope.condition.keyWords = "";
                Object.assign($scope.condition, data);

                getMaterielList(1);
            }

            function clearMaterial() {
                $scope.dataList = [];
            }

            function handleSetMaterial() {
                angular.forEach($scope.dataList, function (item) {
                    item.isSelected = false;
                    angular.forEach($scope.selectedList, function (item2) {
                        if (item[comparedStr] == item2[comparedStr]) {
                            item.isSelected = true;
                        }
                    })
                });
            }

            EventBus.Subscribe("getMaterial", getMaterial);
            EventBus.Subscribe("clearMaterial", clearMaterial);
            EventBus.Subscribe("setMaterial", handleSetMaterial);
            $scope.$on("$destroy", function () {
                EventBus.Unsubscribe("getMaterial", getMaterial);
                EventBus.Unsubscribe("clearMaterial", clearMaterial);
                EventBus.Unsubscribe("setMaterial", handleSetMaterial);
            });

            $scope.cancel = function () {
                closePopup();
            };

            function closePopup() {
                $scope.showToolbar = false;
            }
        }])

        .directive("boxupNoSelector", ['$document', function ($document) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    showToolbar: '=',
                    selectedList: "=",
                    comparedStr: "=",
                },
                controller: 'BoxupNoSelectorCtrl',
                templateUrl: "js/directive/tpl/boxupNoSelector.html",
                link: function (scope, element, attrs) {
                    isAllowI18n(scope);
                }
            }
        }])

        .controller("BoxupNoSelectorCtrl", ["$scope", "$attrs", "ybHttp", "ybWidget", "$timeout", "UserContextService", "EventBus", "$filter", "MESG_TYPE", function ($scope, $attrs, ybHttp, ybWidget, $timeout, UserContextService, EventBus, $filter, MESG_TYPE) {
            $scope.dataList = [];
            $scope.condition = {};
            $scope.pageInfo = {
                pageSize: 10,
                pageNum: 1,
                curPage: 1,
                totalRows: 0,
                totalPages: 0,
                hidePageJump: true,
                hidePageNo: true
            };

            let comparedStr = $scope.comparedStr ? $scope.comparedStr : 'id';

            // 数据预处理
            angular.forEach($scope.selectedList, function (item) {
                if (item.deliveryStatus == 1) {
                    item.itemDisabled = true;
                }
            })
            function getBoxupData(curPage) {
                var service = "device";
                var reqUrl = "/boxup/getBoxupData";
                var param = {};
                param.pageSize = $scope.pageInfo.pageSize;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }
                param.pageNum = $scope.pageInfo.curPage;
                param.filters = {
                    boxupNo: $scope.condition.boxupNo,
                    purchaseContractNo: $scope.condition.purchaseContractNo,
                    deliveryReceiptNo: $scope.condition.deliveryReceiptNo,
                };
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }

                    if (!resp.value) {
                        resp.value = { list: [] }
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.isChecked = false;
                        angular.forEach($scope.selectedList, function (item2) {
                            if (item[comparedStr] == item2[comparedStr]) {
                                item.isChecked = true;
                            }
                        })
                        item.createTimeShow = $filter("YbDate")(item.createTime, "yyyy-MM-dd HH:mm:ss");
                        item.deliveryStatusShow = item.deliveryStatus == 1 ? '已发运' : '未发运';
                        item.weightInfo = `${item.roughWeight || ''}/${item.weight || ''}`
                        item.sizeInfo = `${item.lenghtNum || ''}/${item.withNum || ''}/${item.hightNum || ''}`
                    });
                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                });
            }

            $scope.search = UserContextService.Debounce(function () {
                getBoxupData(1);
            }, 500);

            $scope.changePage = function (curPage) {
                getBoxupData(curPage);
            };
            $scope.selectRow = function (item) {
                // 选中
                if (item.isChecked) {
                    if ($scope.selectedList[0] && $scope.selectedList[0].country != item.country) {
                      item.isChecked = false;
                      ybWidget.ShowMessage('请选择相同国家的箱单', MESG_TYPE.Error);
                      return;
                    }
                    $scope.selectedList.push(item);
                    return;
                }
                // 取消选中
                for (var i = 0; i < $scope.selectedList.length; i++) {
                    if ($scope.selectedList[i][comparedStr] == item[comparedStr]) {
                        $scope.selectedList.splice(i, 1);
                    }
                }
            };

            EventBus.Subscribe("getBoxupData", getBoxupData);
            $scope.$on("$destroy", function () {
                EventBus.Unsubscribe("getBoxupData", getBoxupData);
            });

            $scope.cancel = function () {
                closePopup();
            };

            function closePopup() {
                $scope.showToolbar = false;
            }
        }])

        .directive("billSelector", ["$document", "$timeout", "ybHttp", "ybWidget", function ($document, $timeout, ybHttp, ybWidget) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    dataModel: "=?ngModel", //  绑定数据模型
                    selCode: "=?",
                    selKey: "@",
                    optionChanged: "&", //  选中选项触发 / Function
                    allowSearch: "=", //  支持搜索
                },
                transclude: true,
                templateUrl: "js/directive/tpl/billSelector.html",
                link: function (scope, element, attrs) {
                    scope.name = attrs.name;
                    scope.showPopup = false;
                    scope.optionsList = [];

                    function getList4JckDomestic() {
                        var service = "device";
                        var reqUrl = "/deliveryReceipt/list4JckDomestic";
                        var reqParam = {
                            pageNum: 1,
                            pageSize: 1000,
                            filters: { isDelivery: 1, outStatus: 2, isLinked: 0 }
                        };
                        ybHttp.Post(service, reqUrl, reqParam).then(function (resp) {
                            if (resp.code !== 0) {
                                ybWidget.ShowMessage(resp);
                                return;
                            }
                            angular.forEach(resp.value.list,function(item){
                                item.name = item.billNo
                            })
                            scope.optionsList = resp.value.list;
                            scope.optionsListOrigin = angular.copy(resp.value.list);
                            scope.showPopup = true;
                            if (!!scope.dataModel) {
                                setSelectedRow();
                            }
                        });
                    }
                    function getOrderDataList() {
                        var service = "device";
                        var reqUrl = "/saleIntention/list";
                        var param = {
                            pageNum: 1,
                            pageSize: 1000,
                            filters: { deliveryListFlag: 1 }
                        };
                        ybHttp.Post(service, reqUrl, param).then(function (resp) {
                            if (resp.code !== 0) {
                                ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                                return;
                            }
                            angular.forEach(resp.value.list,function(item){
                                item.name = item.saleNo
                            })
                            scope.optionsList = resp.value.list;
                            scope.optionsListOrigin = angular.copy(resp.value.list);
                            scope.showPopup = true;
                            if (!!scope.dataModel) {
                                setSelectedRow();
                            }
                        });
                    }
                    // 查询进出口运单
                    function getList4JckOverseas() {
                        var service = "device";
                        var reqUrl = "/deliveryReceipt/list4JckOverseas";
                        var param = {
                            pageNum: 1,
                            pageSize: 1000,
                            filters: { deliveryStatus: 0 }
                        };
                        ybHttp.Post(service, reqUrl, param).then(function (resp) {
                            if (resp.code !== 0) {
                                ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                                return;
                            }
                            angular.forEach(resp.value.list,function(item){
                                item.name = item.billNo;
                            })
                            scope.optionsList = resp.value.list;
                            scope.optionsListOrigin = angular.copy(resp.value.list);
                            scope.showPopup = true;
                            if (!!scope.dataModel) {
                                setSelectedRow();
                            }
                        });
                    }

                    function setSelectedRow() {
                        for (var i = 0, len = scope.optionsList.length; i < len; i++) {
                            scope.optionsList[i].selected = false;
                            if (scope.dataModel == scope.optionsList[i].name) {
                                scope.optionsList[i].selected = true;
                                break;
                            }
                        }
                    }

                    scope.showOptions = function () {
                        if (!!scope.showPopup) {
                            scope.showPopup = false;
                            return;
                        }

                        scope.optionsList = scope.optionsListOrigin || [];
                        scope.searchVal = null;

                        if (scope.optionsList.length === 0) {
                            if(scope.selKey == "billNoObj"){
                                getList4JckDomestic()
                            }else if(scope.selKey == "saleNo"){
                                getOrderDataList();
                            }else if(scope.selKey == "jckBillNoObj"){
                                getList4JckOverseas();
                            }
                        }

                        $timeout(function () {
                            scope.showPopup = true;
                        }, 0);

                        scope.allowSearch && $timeout(function () {
                            document.getElementById('search-input').focus();
                        }, 200);
                    };

                    scope.selectOption = function (item) {
                        for (var i = 0, len = scope.optionsList.length; i < len; i++) {
                            scope.optionsList[i].selected = false;
                        }
                        if (!item) {
                            scope.dataModel = "";
                            scope.selCode = "";
                        } else {
                            scope.dataModel = item;
                            scope.selCode = item.code;
                            item.selected = true;
                        }
                        if (angular.isDefined(attrs.optionChanged)) {
                            $timeout(function () {
                                scope.optionChanged(item);
                            });
                        }
                        closePopup();
                    };

                    scope.onSearchChange = function (val) {
                        var optionsListT = scope.optionsListOrigin || [];
                        if (!!val) {
                            optionsListT = optionsListT.filter(function(item) {
                                return item.name.includes(val);
                            });
                        }
                        scope.optionsList = optionsListT;
                    };

                    function closePopup() {
                        scope.showPopup = false;
                    }

                    $document.on('click', function (e) {
                        if (!!scope.showPopup && e.target.id !='search-input') {
                            scope.$apply(function () {
                                scope.showPopup = false;
                            });
                        }
                    });
                }
            }
        }])

        .directive("dictionarySelector", ["$document", "$timeout", "ybHttp", "ybWidget", function ($document, $timeout, ybHttp, ybWidget) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    dataModel: "=?ngModel", //  绑定数据模型
                    selCode: "=?",
                    selKey: "@",
                    noTransclude: "=", // 是否不需要插槽
                    onlyView: "=", // 仅不需要插槽时(noTransclude为true)生效
                    optionChanged: "&", //  选中选项触发 / Function
                    isDisabled: "=?"
                },
                transclude: true,
                templateUrl: "js/directive/tpl/dictionarySelector.html",
                link: async function (scope, element, attrs) {

                    isAllowI18n(scope);

                    scope.showPopup = false;
                    scope.optionsList = [];
                    function getOptionsList() {
                        var service = "device";
                        var reqUrl = "/dataDictionary/searchList";
                        var reqParam = {};
                        reqParam.parentCode = scope.selKey;
                        return ybHttp.Post(service, reqUrl, reqParam).then(function (resp) {
                            if (resp.code !== 0) {
                                ybWidget.ShowMessage(resp);
                                return;
                            }
                            scope.optionsList = resp.value || [];
                            return resp.value || [];
                        });
                    }

                    if (scope.noTransclude && scope.selCode) {
                        await getOptionsList();
                        const findRes = scope.optionsList.find(of => of.code == scope.selCode);
                        if (findRes) {
                            scope.dataModel = findRes.name;
                            scope.$apply();
                        }
                    }

                    function setSelectedRow() {
                        for (var i = 0, len = scope.optionsList.length; i < len; i++) {
                            scope.optionsList[i].selected = false;
                            if (scope.dataModel == scope.optionsList[i].name) {
                                scope.optionsList[i].selected = true;
                                break;
                            }
                        }
                    }

                    scope.showOptions = async function () {
                        if (scope.isDisabled) {
                            return;
                        }
                        if (!!scope.showPopup) {
                            scope.showPopup = false;
                            return;
                        }
                        if (scope.optionsList.length === 0) {
                            await getOptionsList();
                        }

                        if (!!scope.dataModel) {
                            setSelectedRow();
                        }

                        $timeout(function () {
                            scope.showPopup = true;
                        }, 0);
                    };

                    scope.selectOption = function (item) {
                        for (var i = 0, len = scope.optionsList.length; i < len; i++) {
                            scope.optionsList[i].selected = false;
                        }
                        if (!item) {
                            scope.dataModel = "";
                            scope.selCode = "";
                        } else {
                            scope.dataModel = item.name;
                            scope.selCode = item.code;
                            item.selected = true;
                        }

                        if (angular.isDefined(attrs.optionChanged)) {
                            $timeout(function () {
                                scope.optionChanged();
                            });
                        }
                        closePopup();
                    };

                    function closePopup() {
                        scope.showPopup = false;
                    }

                    $document.on('click', function () {
                        if (!!scope.showPopup) {
                            scope.$apply(function () {
                                scope.showPopup = false;
                            });
                        }
                    });
                }
            }
        }])

        .directive("enterpriseDictionary", ["$document", "$timeout", "ybHttp", "ybWidget", function ($document, $timeout, ybHttp, ybWidget) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    dataModel: "=?ngModel", //  绑定数据模型
                    selCode: "=?",
                    selKey: "@",
                    optionChanged: "&", //  选中选项触发 / Function
                    isDisabled: "=?"
                },
                transclude: true,
                templateUrl: "js/directive/tpl/dictionarySelector.html",
                link: function (scope, element, attrs) {

                    isAllowI18n(scope);

                    scope.name = attrs.name;
                    scope.showPopup = false;
                    scope.optionsList = [];
                    function getOptionsList() {
                        var service = "device";
                        var reqUrl = "/serviceBasicDataAgent/list";
                        var reqParam = {
                            filters:{},
                        };
                        reqParam.filters = {
                            pCode : scope.selKey
                        }
                        ybHttp.Post(service, reqUrl, reqParam).then(function (resp) {
                            if (resp.code !== 0) {
                                ybWidget.ShowMessage(resp);
                                return;
                            }
                            scope.optionsList = resp.value.list;
                            scope.showPopup = true;
                            if (!!scope.dataModel) {
                                setSelectedRow();
                            }
                        });
                    }

                    function setSelectedRow() {
                        for (var i = 0, len = scope.optionsList.length; i < len; i++) {
                            scope.optionsList[i].selected = false;
                            if (scope.dataModel == scope.optionsList[i].name) {
                                scope.optionsList[i].selected = true;
                                break;
                            }
                        }
                    }

                    scope.showOptions = function () {
                        if (scope.isDisabled) {
                            return;
                        }
                        if (!!scope.showPopup) {
                            scope.showPopup = false;
                            return;
                        }
                        if (scope.optionsList.length === 0) {
                            getOptionsList();
                        }
                        $timeout(function () {
                            scope.showPopup = true;
                        }, 0);
                    };

                    scope.selectOption = function (item) {
                        for (var i = 0, len = scope.optionsList.length; i < len; i++) {
                            scope.optionsList[i].selected = false;
                        }
                        if (!item) {
                            scope.dataModel = "";
                            scope.selCode = "";
                        } else {
                            scope.dataModel = item.name;
                            scope.selCode = item.code;
                            item.selected = true;
                        }

                        if (angular.isDefined(attrs.optionChanged)) {
                            $timeout(function () {
                                scope.optionChanged();
                            });
                        }
                        closePopup();
                    };

                    function closePopup() {
                        scope.showPopup = false;
                    }

                    $document.on('click', function () {
                        if (!!scope.showPopup) {
                            scope.$apply(function () {
                                scope.showPopup = false;
                            });
                        }
                    });
                }
            }
        }])

        .directive("dealerDictionarySelector", ["$document", "$timeout", "ybHttp", "ybWidget", function ($document, $timeout, ybHttp, ybWidget) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    dataModel: "=?ngModel", //  绑定数据模型
                    selCode: "=?",
                    selKey: "@",
                    orgId: "@",
                    optionChanged: "&", //  选中选项触发 / Function
                    allowSearch: "=", //  支持搜索
                    source: "=", // 下拉框数据源
                },
                transclude: true,
                templateUrl: "js/directive/tpl/dictionarySelector.html",
                link: function (scope, element, attrs) {
                    scope.name = attrs.name;
                    scope.showPopup = false;
                    scope.optionsList = [];

                    function getOptionsList(jckFlag) {
                        function handleData(data) {
                            scope.optionsList = data;
                            scope.optionsListOrigin = angular.copy(data);
                            scope.showPopup = !jckFlag;

                            setSelectedRow();
                        }

                        if (angular.isDefined(scope.source)) {
                            handleData(scope.source);
                            return;
                        }

                        var service = "device";
                        var reqUrl = "/serviceBasicDataAgent/searchList";
                        var reqParam = {};
                        reqParam.pCode = scope.selKey;
                        reqParam.orgId = scope.orgId;
                        ybHttp.Post(service, reqUrl, reqParam).then(function (resp) {
                            if (resp.code !== 0) {
                                ybWidget.ShowMessage(resp);
                                return;
                            }

                            handleData(resp.value);
                        });
                    }
                    function setSelectedRow() {
                        if (!scope.dataModel) return;

                        for (var i = 0, len = scope.optionsList.length; i < len; i++) {
                            scope.optionsList[i].selected = false;
                            if (scope.dataModel == scope.optionsList[i].name) {
                                scope.optionsList[i].selected = true;
                                break;
                            }
                        }
                    }

                    scope.showOptions = function () {
                        if (!!scope.showPopup) {
                            scope.showPopup = false;
                            return;
                        }

                        scope.optionsList = scope.optionsListOrigin || [];
                        scope.searchVal = null;

                        if (scope.optionsList.length === 0) {
                            getOptionsList();
                        } else {
                            setSelectedRow();
                        }

                        $timeout(function () {
                            scope.showPopup = true;
                        }, 0);

                        scope.allowSearch && $timeout(function () {
                            document.getElementById('search-input').focus();
                        }, 200);
                    };

                    scope.selectOption = function (item) {
                        for (var i = 0, len = scope.optionsList.length; i < len; i++) {
                            scope.optionsList[i].selected = false;
                        }
                        if (!item) {
                            scope.dataModel = "";
                            scope.selCode = "";
                        } else {
                            scope.dataModel = item.name;
                            scope.selCode = item.code;
                            item.selected = true;
                        }
                        if (angular.isDefined(attrs.optionChanged)) {
                            $timeout(function () {
                                scope.optionChanged();
                            });
                        }
                        closePopup();
                    };

                    scope.onSearchChange = function (val) {
                        var optionsListT = scope.optionsListOrigin || [];
                        if (!!val) {
                            optionsListT = optionsListT.filter(function(item) {
                                return item.name.includes(val);
                            });
                        }
                        scope.optionsList = optionsListT;
                    };

                    function closePopup() {
                        scope.showPopup = false;
                    }

                    $document.on('click', function (e) {
                        if (!!scope.showPopup && e.target.id !='search-input') {
                            scope.$apply(function () {
                                scope.showPopup = false;
                            });
                        }
                    });

                    scope.$watch("orgId", function (value, oldValue) {
                        getOptionsList(true);
                    });
                }
            }
        }])

        .directive("multiSelector", ['$document', function ($document) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    mtPlaceholder: "@?",
                    mtName: "@",
                    mtValue: "@",
                    mtDatas: "=",
                    mtChange: "&?",
                    multiId: "=?",
                    multiName: "=?",
                    multiValue: "=",
                    isJckFlag :'='
                },
                controller: 'MultiSelectorCtrl',
                templateUrl: "js/directive/tpl/multiSelector.html",
                link: function ($scope, element, attrs) {
                    $scope.$watch('multiValue', function (multiValue) {
                        // 重置时 输入框的名称未清空
                        if (!multiValue) {
                            $scope.multiName = ''
                        }
                    })
                    angular.element($document[0].querySelector('.more-toolbar')).on('click', function () {
                        cancelPopup();
                    });

                    $document.on('click', function () {
                        cancelPopup();
                    });
                    function cancelPopup() {
                        if (!!$scope.enableMultiSelectorPopup) {
                            $scope.$apply(function () {
                                $scope.enableMultiSelectorPopup = false;
                            });
                        }
                    }
                }
            }
        }])
        .controller("MultiSelectorCtrl", ["$scope", "$attrs", "ybHttp", "ybWidget", "$timeout", "MESG_TYPE", function ($scope, $attrs, ybHttp, ybWidget, $timeout, MESG_TYPE) {
            $scope.enableMultiSelectorPopup = false;
            $scope.upPosition = false;
            $scope.toggleDropDown = function () {
                if (!!$scope.enableMultiSelectorPopup) {
                    return;
                }
                dataInit();
                $timeout(function () {
                    $scope.enableMultiSelectorPopup = true;
                });
            };

            function dataInit() {
                var multiArr
                if ($scope.isJckFlag) {
                    multiArr = $scope.multiValue || []
                }else {
                    multiArr = $scope.multiValue ? $scope.multiValue.split(",") : [];
                }
                angular.forEach($scope.mtDatas, function (item) {
                    if (isExist(item[$scope.mtValue], multiArr)) {
                        item.isChecked = true;
                    } else {
                        item.isChecked = false;
                    }
                });
            }

            function isExist(str, arr) {
                var isExist = false;
                for (var i = 0; i < arr.length; i++) {
                    if (str === arr[i]) {
                        isExist = true;
                        break
                    }
                }
                return isExist;
            }

            $scope.ok = function () {
                var multiIdArr = [],
                    multiNameArr = [],
                    multiValueArr = [];
                angular.forEach($scope.mtDatas, function (item) {
                    if (item.isChecked) {
                        multiIdArr.push(item['id']);
                        multiNameArr.push(item[$scope.mtName]);
                        multiValueArr.push(item[$scope.mtValue]);
                    }
                });
                $scope.multiId = multiIdArr.join(",");
                $scope.multiName = multiNameArr.join(",");
                // 进出口直接返回 不用处理处理
                $scope.multiValue = $scope.isJckFlag ?  multiValueArr : multiValueArr.join(",");

                $timeout(function () {
                    $scope.mtChange();
                });
                closePopup();
            };

            $scope.cancel = function () {
                closePopup();
            };

            function closePopup() {
                $scope.enableMultiSelectorPopup = false;
            }
        }])

        .directive("innerOrderAutoComplete", [function () {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    dataModel: '=?ngModel',
                    optionList: "=",
                    bindKey: "@"
                },
                controller: 'InnerOrderAutoCompleteCtrl',
                templateUrl: "js/directive/tpl/innerOrderAutoComplete.html"
            }
        }])
        .controller("InnerOrderAutoCompleteCtrl", ["$scope", function ($scope) {

            isAllowI18n($scope);

            $scope.key = $scope.bindKey || "innerOrder";
            $scope.fu = function () {
                document.getElementById("inputSelect").value = $scope.selectone ? $scope.selectone[$scope.key] : "";
                $scope.dataModel = angular.copy($scope.selectone);
            };
            $scope.gu = function () {
                $scope.selectone = null;

                var obj = {};
                var flag = false;
                for (var i = 0; i < $scope.optionList.length; i++) {
                    if ($scope.optionList[i][$scope.key] == $scope.dataModel[$scope.key]) {
                        obj = angular.copy($scope.optionList[i]);
                        flag = true
                        break;
                    }
                }
                if (!flag) {
                    obj[$scope.key] = $scope.dataModel[$scope.key];
                }
                $scope.dataModel = obj;
            }
        }])
        .directive("bjMultiSelector", ['$document', function ($document) {
            return {
                restrict: "EA",
                replace: "true",
                require: "?ngModel",
                scope: {
                    selectedItem: "=?ngModel", // {ids:[]} ids数组中是上次所选的数据
                    dataList: "=valueList",
                    isRequired: "=",
                    placeholder: "@",
                    idsKey: "@", // 后端所需数据在 下拉框数据源中 对应的字段key
                    labelKey: "@", // 下拉框数据源展示的label字段key
                    allowSearch: "=?", // 是否支持搜索（默认支持）
                    searchKey: "@", // 支持搜索时使用的搜索字段key
                    bjClick: "&",
                },
                controller: 'BjMultiSelectorCtrl',
                templateUrl: "js/directive/tpl/bjMultiSelector.html",
                link: function ($scope, element, attrs, ctrl) {

                    isAllowI18n($scope);

                    $document.on('click', function () {
                        if (!!$scope.enablePopup) {
                            $scope.$apply(function () {
                                $scope.enablePopup = false;
                            });
                        }
                    });

                    $scope.$watch('isRequired', function() {
                        validateFun($scope.selectedItem, true);
                    })

                    function validateFun(value, fromWatch) {
                        if ($scope.isRequired) {
                            if (!value.ids || value.ids.length == 0) {
                                ctrl.$dirty = !!value.ids && !fromWatch;
                                ctrl.$setValidity("required", false);
                            } else {
                                ctrl.$setValidity("required", true);
                            }
                        } else {
                            ctrl.$setValidity("required", true);
                        }
                        return value;
                    }

                    ctrl.$formatters.unshift(validateFun)
                }
            }
        }])
        .controller("BjMultiSelectorCtrl", ["$scope", "$attrs", "$timeout", function ($scope, $attrs, $timeout) {
            $scope.placeholderT = $scope.placeholder || '请选择';
            $scope.idsKeyT = $scope.idsKey || 'id';
            $scope.labelKeyT = $scope.labelKey || 'name';

            $scope.allowSearch = $scope.allowSearch || true;
            $scope.searchKeyT = $scope.searchKey || $scope.labelKeyT;

            $scope.enablePopup = false;
            $scope.upPosition = angular.isDefined($attrs.popupPosition) ? ($attrs.popupPosition == 'up') : false;

            if (angular.isUndefined($scope.selectedItem)) {
                $scope.selectedItem = { ids: [] };
            } else if (angular.isUndefined($scope.selectedItem.ids)) {
                $scope.selectedItem.ids = [];
            }
            
            $scope.$watch('selectedItem.ids + dataList', function() {
                console.log('selectedItem.ids or dataList changed');
                setDefaultValues();
            }, true);

            function setDefaultValues () {
                $scope.searchVal = '';

                const datasTemp = $scope.dataList;
                var selectedItemTemp = angular.copy($scope.selectedItem) || {};
                if (!!datasTemp && datasTemp.length > 0) {
                    const selNamesTemp = [];
                    for (var d of datasTemp) {
                        d.isHidden = false;
                        d.isChecked = !!selectedItemTemp.ids && selectedItemTemp.ids.includes(d[$scope.idsKeyT]);
                        d.isChecked && selNamesTemp.push(d[$scope.labelKeyT])
                    }
                    $scope.markInfo.allChecked = checkAll();
                    $scope.selectedNamesStr = selNamesTemp.join(',');
                }
            }

            $scope.toggleDropDown = function () {
                if (angular.isDefined($attrs.bjClick) && !$scope.bjClick()) {
                    return
                }

                // 也可以在此 初始化数据源、默认值。本组件采用的是 $scope.$watch('selectedItem.ids + dataList', function() {}) 来实现的

                if (!$scope.enablePopup) {
                    $timeout(function () {
                        $scope.enablePopup = true;
                    });
                }
            };

            $scope.markInfo = {
                allChecked: false
            };

            $scope.selectAll = function () {
                for (const item of $scope.dataList) {
                    if (item.isHidden) { continue; }
                    item.isChecked = $scope.markInfo.allChecked;
                }
            };

            $scope.selectSingle = function (item) {
                if (!item.isChecked) {
                    $scope.markInfo.allChecked = false;
                } else {
                    $scope.markInfo.allChecked = checkAll();
                }
            };

            function checkAll() {
                var selectAllFlag = false;
                for (const item of $scope.dataList) {
                    if (item.isHidden) { continue; }
                    if (!item.isChecked) {
                        selectAllFlag = false;
                        break;
                    }
                    selectAllFlag = true;
                }
                return selectAllFlag;
            }

            $scope.ok = function () {
                var selDatas = $scope.dataList.filter(f => f.isChecked);
                $scope.selectedItem = {
                    ids: selDatas.map(m => m[$scope.idsKeyT])
                };
                // $scope.selectedNamesStr = selDatas.map(m => m[$scope.labelKeyT]).join(',');
                closePopup();
            };

            $scope.cancel = function () {
                closePopup();
            };

            function closePopup() {
                $scope.enablePopup = false;
            }

            $scope.datasShowLength = $scope.dataList?.length || 0;
            $scope.onSearchChange = function (val) {
                $scope.dataList.forEach((item) => {
                    item.isHidden = !item[$scope.searchKeyT].includes(val);
                });
                $scope.datasShowLength = $scope.dataList.filter(d => !d.isHidden).length;
                $scope.markInfo.allChecked = checkAll();
            };
        }])
        .directive("bjSelect", ["$document", "$timeout", function ($document, $timeout) {
            return {
                restrict: "EA",
                replace: "true",
                scope: {
                    dataModel: "=?ngModel", // 绑定数据模型
                    isModelObject: "=?", // 绑定数据模型 是否是 对象类型
                    bindKey: "@", // 页面已选择(已双向绑定)的数据(dataModel) 和 下拉框数据源每一项 唯一对应时，使用到的字段key

                    source: "=", // 下拉框数据源
                    sourceLabelKey: "@", // 下拉框数据源展示的label字段key

                    allowSearch: "=?", // 是否支持搜索（默认支持）
                    searchKey: "@", // 支持搜索时使用的搜索字段key

                    disabled: "=?", // 是否禁用
                    onOptionChanged: "&", // 选中选项触发 / Function
                    onClick: "&", // 点击请选择时 触发 / Function
                },
                templateUrl: "js/directive/tpl/bjSelect.html",
                link: function (scope, element, attrs, ctrl) {
                    scope.showPopup = false;

                    scope.isModelObjectT = angular.isDefined(scope.isModelObject) ? scope.isModelObject : true;

                    scope.bindKeyT = scope.bindKey || 'id';
                    scope.sourceLabelKeyT = scope.sourceLabelKey || 'name';
                    scope.allowSearchT = angular.isDefined(scope.allowSearch) ? scope.allowSearch : true;
                    scope.searchKeyT = scope.searchKey || scope.sourceLabelKeyT;

                    function getModelValue() {
                        return scope.isModelObjectT ? scope.dataModel?.[scope.bindKeyT] : scope.dataModel;
                    }

                    function setModelValue(val) {
                        scope.isModelObjectT ? scope.dataModel = val : scope.dataModel = val[scope.bindKeyT];
                    }

                    scope.$watch('source', function(newVal, oldVal) {
                        if (newVal && !oldVal && getModelValue()) {
                            // 初始化已选中的项
                            setModelValue(newVal.find(o => o[scope.bindKeyT] == getModelValue()));
                        }
                    })

                    function setSelectedRow() {
                        for (var i = 0, len = scope.optionsList.length; i < len; i++) {
                            const o = scope.optionsList[i];
                            o.selected = false;
                            if (o[scope.bindKeyT] == getModelValue()) {
                                o.selected = true;
                                break;
                            }
                        }
                    }

                    scope.showOptions = function () {
                        if (angular.isDefined(attrs.onClick)) {
                            scope.onClick();
                        }

                        if (scope.disabled) {
                            return;
                        }

                        if (!!scope.showPopup) {
                            scope.showPopup = false;
                            return;
                        }

                        scope.optionsList = angular.copy(scope.source) || [];
                        scope.searchVal = null;

                        if (!!getModelValue()) {
                            setSelectedRow();
                        }

                        $timeout(function () {
                            scope.showPopup = true;
                        }, 0);

                        if (scope.allowSearchT) {
                            $timeout(function () {
                                document.getElementById('search-input').focus();
                            }, 200);
                        }
                    };

                    scope.selectOption = function (item) {
                        for (var i = 0, len = scope.optionsList.length; i < len; i++) {
                            scope.optionsList[i].selected = false;
                        }
                        if (!item) {
                            scope.dataModel = null;
                        } else {
                            setModelValue(item);
                            item.selected = true;
                        }
                        if (angular.isDefined(attrs.onOptionChanged)) {
                            $timeout(function () {
                                scope.onOptionChanged(item);
                            });
                        }
                        closePopup();
                    };

                    scope.onSearchChange = function (val) {
                        var optionsListT = angular.copy(scope.source) || [];
                        if (!!val) {
                            optionsListT = optionsListT.filter(function(item) {
                                return item[scope.searchKeyT].includes(val);
                            });
                        }
                        scope.optionsList = optionsListT;
                    };

                    function closePopup() {
                        scope.showPopup = false;
                    }

                    $document.on('click', function (e) {
                        if (!!scope.showPopup && e.target.id !='search-input') {
                            scope.$apply(function () {
                                scope.showPopup = false;
                            });
                        }
                    });
                }
            }
        }])
        .directive("hyLayout", ["$document", "$timeout", function ($document, $timeout) {
            /* 使用示例代码：
                <hy-layout>
                    <hy-form-extra>
                    </hy-form-extra>
                    <hy-layout-form>
                    </hy-layout-form>
                    <hy-table-extra>
                    </hy-table-extra>
                    <hy-table-operation>
                    </hy-table-operation>
                    <hy-layout-table>
                    </hy-layout-table>
                    <hy-layout-footer>
                    </hy-layout-footer>
                </hy-layout>
            */

            /* 使用中的问题，暂时使用一下方法解决

                问题1：插槽内 基本类型的变量无法使用，如costPriceShow
                    方法一：$parent.costPriceShow
                    方法二：改成父作用域内的对象----> js：$scope.slotData={}; html：slotData.costPriceShow
            */
            return {
                restrict: "EA",
                transclude: {
                    'hyFormNavExtra': '?hyFormNavExtra',
                    'hyForm': '?hyLayoutForm',
                    'hyTableNavExtra': '?hyTableNavExtra',
                    'hyTableOperation': '?hyTableOperation',
                    'hyTable': '?hyLayoutTable',
                    'hyTableFixed': '?hyLayoutTableFixed',
                    'hyFooter': '?hyLayoutFooter'
                },
                templateUrl: "js/directive/tpl/hyLayOut.html",
            }
        }])
        ;
})(window, window.angular);
